<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content>
    <meta name="keyword" content>
    <link rel="shortcut icon" href="/img/ironman-draw.png">
    <!-- Place this tag in your head or just before your close body tag. -->
    <script async defer src="https://buttons.github.io/buttons.js"></script>
    <title>
        
          ASP.NET MVC+EF 项目架构搭建 - xyzko1 | 博客
        
    </title>

    <link rel="canonical" href="https://xyzko1.github.io/2018/02/01/ASP.NET MVC+EF 项目架构搭建/">

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <!-- Custom CSS --> 
    <link rel="stylesheet" href="/css/beantech.min.css">
    
    <!-- Pygments Highlight CSS -->
    <link rel="stylesheet" href="/css/highlight.css">

    <link rel="stylesheet" href="/css/widget.css">

    <link rel="stylesheet" href="/css/rocket.css">

    <link rel="stylesheet" href="/css/signature.css">

    <link rel="stylesheet" href="/css/toc.css">

    <!-- Custom Fonts -->
    <!-- <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> -->
    <!-- Hux change font-awesome CDN to qiniu -->
    <link href="https://cdn.staticfile.org/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">


    <!-- Hux Delete, sad but pending in China
    <link href='http://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/
    css'>
    -->


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- ga & ba script hoook -->
    <script></script>
</head>


<!-- hack iOS CSS :active style -->
<body ontouchstart="">
	<!-- Modified by Yu-Hsuan Yen -->
<!-- Post Header -->
<style type="text/css">
    header.intro-header{
        
            background-image: url('Demo.png')
            /*post*/
        
    }
    
    #signature{
        background-image: url('/img/signature/BeanTechSign-white.png');
    }
    
</style>

<header class="intro-header" >
    <!-- Signature -->
    <div id="signature">
        <div class="container">
            <div class="row">
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                
                    <div class="post-heading">
                        <div class="tags">
                            
                              <a class="tag" href="/tags/#Hexo" title="Hexo">Hexo</a>
                            
                              <a class="tag" href="/tags/#Blog" title="Blog">Blog</a>
                            
                        </div>
                        <h1>ASP.NET MVC+EF 项目架构搭建</h1>
                        <h2 class="subheading"></h2>
                        <span class="meta">
                            Posted by xyzko1 on
                            2018-02-01
                        </span>
                    </div>
                


                </div>
            </div>
        </div>
    </div>
</header>

	
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">xyz的博客</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <!-- Known Issue, found by Hux:
            <nav>'s height woule be hold on by its content.
            so, when navbar scale out, the <nav> will cover tags.
            also mask any touch event of tags, unfortunately.
        -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/">Home</a>
                    </li>

                    

                        
                    

                        
                        <li>
                            <a href="/about/">About</a>
                        </li>
                        
                    

                        
                        <li>
                            <a href="/tags/">Tags</a>
                        </li>
                        
                    

                        
                        <li>
                            <a href="/archive/">Archives</a>
                        </li>
                        
                    
                    
                </ul>
            </div>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        // CLOSE
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        // OPEN
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>


    <!-- Main Content -->
    <!-- Modify by Yu-Hsuan Yen -->

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Post Container -->
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                post-container">

                <blockquote>
<p>created by <a href="https://github.com/xyzko1/xyzko1.github.io" target="_blank" rel="noopener">xyzko1</a><br>
2018年02月01日 14:00:10</p>
</blockquote>
<h1><span id="正文">正文</span></h1>
<hr>
<p>新建MVC项目UI<br>
<img src="1.png" alt="avatar"></p>
<hr>
<p>然后分别建立类库，Model,IDAL,DALFactory,DAL,IBLL,BLL,Common<br>
<img src="2.png" alt="avatar"></p>
<hr>
<p>Model里面添加EF实体 User生成数据库<br>
<img src="3.png" alt="avatar"></p>
<p>Model里面添加EF实体 User生成数据库<br>
<img src="4.png" alt="avatar"></p>
<hr>
<p>IDAL层<br>
IBasedal.cs</p>
<figure class="highlight xquery"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">using System;</span><br><span class="line">using System.Collections.Generic;</span><br><span class="line">using System.Linq;</span><br><span class="line">using System.Text;</span><br><span class="line">using System.Threading.Tasks;</span><br><span class="line"> </span><br><span class="line"><span class="type">namespace</span> IDAL</span><br><span class="line">&#123;</span><br><span class="line">   public  interface IBaseDal<span class="xml"><span class="tag">&lt;<span class="name">T</span>&gt;</span></span></span><br><span class="line"><span class="xml">    </span><span class="xquery">&#123;</span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">summary</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// </span></span><br><span class="line"><span class="xquery">        /// &lt;/summary&gt;</span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">param</span> <span class="attr">name</span>=<span class="string">"whereLambda"</span>&gt;</span><span class="tag">&lt;/<span class="name">param</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">returns</span>&gt;</span><span class="tag">&lt;/<span class="name">returns</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        IQueryable<span class="xml"><span class="tag">&lt;<span class="name">T</span>&gt;</span> LoadEntities(System.Linq.Expressions.Expression<span class="tag">&lt;<span class="name">Func</span>&lt;<span class="attr">T</span>, <span class="attr">bool</span>&gt;</span>&gt; whereLambda);</span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">summary</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// </span></span><br><span class="line"><span class="xquery">        /// &lt;/summary&gt;</span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">typeparam</span> <span class="attr">name</span>=<span class="string">"s"</span>&gt;</span><span class="tag">&lt;/<span class="name">typeparam</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">param</span> <span class="attr">name</span>=<span class="string">"pageIndex"</span>&gt;</span><span class="tag">&lt;/<span class="name">param</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">param</span> <span class="attr">name</span>=<span class="string">"pageSize"</span>&gt;</span><span class="tag">&lt;/<span class="name">param</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">param</span> <span class="attr">name</span>=<span class="string">"totalCount"</span>&gt;</span><span class="tag">&lt;/<span class="name">param</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">param</span> <span class="attr">name</span>=<span class="string">"wherelambda"</span>&gt;</span><span class="tag">&lt;/<span class="name">param</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">param</span> <span class="attr">name</span>=<span class="string">"orderByLambda"</span>&gt;</span><span class="tag">&lt;/<span class="name">param</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">param</span> <span class="attr">name</span>=<span class="string">"isasc"</span>&gt;</span><span class="tag">&lt;/<span class="name">param</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        /// <span class="xml"><span class="tag">&lt;<span class="name">returns</span>&gt;</span><span class="tag">&lt;/<span class="name">returns</span>&gt;</span></span></span></span><br><span class="line"><span class="xquery">        IQueryable<span class="xml"><span class="tag">&lt;<span class="name">T</span>&gt;</span> LoadPageEntities</span><span class="xml"><span class="tag">&lt;<span class="name">s</span>&gt;</span>(int pageIndex, int pageSize, out int totalCount, System.Linq.Expressions.Expression<span class="tag">&lt;<span class="name">Func</span>&lt;<span class="attr">T</span>, <span class="attr">bool</span>&gt;</span>&gt; wherelambda, System.Linq.Expressions.Expression<span class="tag">&lt;<span class="name">Func</span>&lt;<span class="attr">T</span>, <span class="attr">s</span>&gt;</span>&gt; orderByLambda, bool isasc);</span></span></span><br><span class="line"><span class="xquery">        bool DeleteEntity(T entity);</span></span><br><span class="line"><span class="xquery">        bool EditEntity(T entity);</span></span><br><span class="line"><span class="xquery">        T AddEntity(T entity);</span></span><br><span class="line"><span class="xquery">    &#125;</span></span><br><span class="line"><span class="xml">&#125;</span></span><br></pre></td></tr></table></figure>
<p>IUserDal.cs实现IBaseDal接口：</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">using System;</span><br><span class="line">using System.Collections.Generic;</span><br><span class="line">using System.Linq;</span><br><span class="line">using System.Text;</span><br><span class="line">using System.Threading.Tasks;</span><br><span class="line">using Model;</span><br><span class="line">namespace IDAL</span><br><span class="line">&#123;</span><br><span class="line">   public <span class="built_in"> interface </span>IUserDal:IBaseDal&lt;User&gt;</span><br><span class="line">    &#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">IDbSession.cs接口(回话层接口DALFactory)</span><br><span class="line">using System;</span><br><span class="line">using System.Collections.Generic;</span><br><span class="line">using System.Data.Entity;</span><br><span class="line">using System.Linq;</span><br><span class="line">using System.Text;</span><br><span class="line">using System.Threading.Tasks;</span><br><span class="line"> </span><br><span class="line">namespace IDAL</span><br><span class="line">&#123;</span><br><span class="line">    public<span class="built_in"> interface </span> IDbSession</span><br><span class="line">    &#123;</span><br><span class="line">        DbContext db &#123; get; &#125;</span><br><span class="line">        IUserDal userdal &#123; get; set; &#125;</span><br><span class="line">        bool SaveChanges();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>IDbSession.cs接口(回话层接口DALFactory)</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">using System;</span><br><span class="line">using System.Collections.Generic;</span><br><span class="line">using System.Data.Entity;</span><br><span class="line">using System.Linq;</span><br><span class="line">using System.Text;</span><br><span class="line">using System.Threading.Tasks;</span><br><span class="line"> </span><br><span class="line">namespace IDAL</span><br><span class="line">&#123;</span><br><span class="line">    public<span class="built_in"> interface </span> IDbSession</span><br><span class="line">    &#123;</span><br><span class="line">        DbContext db &#123; get; &#125;</span><br><span class="line">        IUserDal userdal &#123; get; set; &#125;</span><br><span class="line">        bool SaveChanges();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="5.png" alt="avatar"></p>
<p>DALFactory(数据回话层)<br>
DBSession.cs实现IDBSession</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"><span class="keyword">using</span> IDAL;</span><br><span class="line"><span class="keyword">using</span> DAL;</span><br><span class="line"><span class="keyword">namespace</span> <span class="title">DALFactory</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">class</span> <span class="title">DBSession</span> : <span class="title">IDbSession</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">public</span> System.Data.Entity.DbContext db</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">get</span> &#123;</span><br><span class="line">                <span class="keyword">return</span> DBContextFactory.CReateDbContext();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">private</span> IUserDal _UserDAl;</span><br><span class="line">       <span class="keyword">public</span> IUserDal userdal &#123; <span class="keyword">get</span> =&gt;AbstractFactorycs.createIUserDal(); <span class="keyword">set</span> =&gt; _UserDAl=<span class="keyword">value</span>; &#125;</span><br><span class="line"> </span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">SaveChanges</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line">            <span class="keyword">return</span> db.SaveChanges() &gt; <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>DBSessionFactory.cs DBsession的工厂</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Runtime.Remoting.Messaging;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"><span class="keyword">using</span> IDAL;</span><br><span class="line"><span class="keyword">namespace</span> <span class="title">DALFactory</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span>   <span class="keyword">class</span> <span class="title">DBSessionFactory</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> IDbSession <span class="title">CreateDBSession</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line">            <span class="comment">//面向接口编程 返回接口</span></span><br><span class="line">            IDbSession   dbsession =(IDbSession) CallContext.GetData(<span class="string">"dbsession"</span>);</span><br><span class="line">            <span class="keyword">if</span> (dbsession == <span class="literal">null</span>)</span><br><span class="line">            &#123;</span><br><span class="line">               dbsession = <span class="keyword">new</span> DBSession();</span><br><span class="line">                CallContext.SetData(<span class="string">"dbsession"</span>, dbsession);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> dbsession;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>AbstractFactory.cs(DAL的抽象工厂 利用反射创建DAL)</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"><span class="keyword">using</span> System.Configuration;</span><br><span class="line"><span class="keyword">using</span> System.Reflection;</span><br><span class="line"><span class="keyword">using</span> IDAL;</span><br><span class="line"><span class="keyword">using</span> DAL;</span><br><span class="line"><span class="keyword">namespace</span> <span class="title">DALFactory</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">class</span> <span class="title">AbstractFactorycs</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="keyword">string</span> AssemblyPath = ConfigurationManager.AppSettings[<span class="string">"AssemblyPath"</span>];</span><br><span class="line">        <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">readonly</span> <span class="keyword">string</span> NameSpace = ConfigurationManager.AppSettings[<span class="string">"NameSpace"</span>];</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> IUserDal <span class="title">createIUserDal</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line">            <span class="keyword">string</span> fullclassname = NameSpace + <span class="string">".UserDal"</span>;</span><br><span class="line">            <span class="keyword">return</span> (IUserDal)CreateInstace(fullclassname);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">object</span> <span class="title">CreateInstace</span>(<span class="params"><span class="keyword">string</span> classname</span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line">            <span class="keyword">var</span> assembly = Assembly.Load(AssemblyPath);<span class="comment">//这里加载的是程序集名称 如DAL</span></span><br><span class="line">            <span class="keyword">return</span> assembly.CreateInstance(classname);<span class="comment">//这里需要填写 命名空间.类名</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="6.png" alt="avatar"></p>
<p>DAL层<br>
DBContextFactory.cs (EF Context线程内唯一对象)</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Data.Entity;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Runtime.Remoting.Messaging;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"><span class="keyword">using</span> Model;</span><br><span class="line"><span class="keyword">namespace</span> <span class="title">DAL</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span>  <span class="keyword">class</span> <span class="title">DBContextFactory</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> DbContext <span class="title">CReateDbContext</span>(<span class="params"></span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line"> </span><br><span class="line">            DbContext dbcontext = (DbContext)CallContext.GetData(<span class="string">"dbContext"</span>);</span><br><span class="line">            <span class="keyword">if</span> (dbcontext == <span class="literal">null</span>)</span><br><span class="line">            &#123;</span><br><span class="line">                dbcontext = <span class="keyword">new</span> MYMVCOAContainer();</span><br><span class="line">                CallContext.SetData(<span class="string">"dbContext"</span>, dbcontext);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> dbcontext;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>UserDal(具体的dal类，实现IUserDAL接口)</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"><span class="keyword">using</span> Model;</span><br><span class="line"><span class="keyword">using</span> IDAL;</span><br><span class="line"><span class="keyword">using</span> System.Linq.Expressions;</span><br><span class="line"><span class="keyword">using</span> System.Data.Entity;</span><br><span class="line"><span class="keyword">namespace</span> <span class="title">DAL</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">class</span> <span class="title">UserDal</span> :<span class="title">IUserDal</span></span><br><span class="line">    &#123;</span><br><span class="line">        MYMVCOAContainer db =(MYMVCOAContainer) DBContextFactory.CReateDbContext();</span><br><span class="line">        <span class="function"><span class="keyword">public</span> User <span class="title">AddEntity</span>(<span class="params">User entity</span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line">            db.UserSet.Add(entity);</span><br><span class="line">            db.SaveChanges();</span><br><span class="line">            <span class="keyword">return</span> entity;</span><br><span class="line">        &#125;</span><br><span class="line"> </span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">DeleteEntity</span>(<span class="params">User entity</span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line">            db.UserSet.Remove(entity);</span><br><span class="line">           <span class="keyword">return</span>  db.SaveChanges()&gt;<span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line"> </span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">EditEntity</span>(<span class="params">User entity</span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line">            db.Entry&lt;User&gt;(entity).State = System.Data.Entity.EntityState.Modified;</span><br><span class="line">            <span class="keyword">return</span> db.SaveChanges() &gt; <span class="number">0</span>;</span><br><span class="line">        &#125;</span><br><span class="line"> </span><br><span class="line">        <span class="function"><span class="keyword">public</span> IQueryable&lt;User&gt; <span class="title">LoadEntities</span>(<span class="params">Expression&lt;Func&lt;User, <span class="keyword">bool</span>&gt;&gt; whereLambda</span>)</span></span><br><span class="line"><span class="function"></span>        &#123;</span><br><span class="line">            <span class="keyword">return</span> db.UserSet.Where(whereLambda);</span><br><span class="line">        &#125;</span><br><span class="line"> </span><br><span class="line">        <span class="keyword">public</span> IQueryable&lt;User&gt; LoadPageEntities&lt;s&gt;(<span class="keyword">int</span> pageIndex, <span class="keyword">int</span> pageSize, <span class="keyword">out</span> <span class="keyword">int</span> totalCount, Expression&lt;Func&lt;User, <span class="keyword">bool</span>&gt;&gt; wherelambda, Expression&lt;Func&lt;User, s&gt;&gt; orderByLambda, <span class="keyword">bool</span> isasc)</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="keyword">var</span> temp = db.UserSet.Where(wherelambda);</span><br><span class="line">            totalCount = temp.Count();</span><br><span class="line">            <span class="keyword">if</span> (isasc)</span><br><span class="line">            &#123;</span><br><span class="line">                temp = temp.OrderBy&lt;User, s&gt;(orderByLambda).Skip&lt;User&gt;(pageIndex - <span class="number">1</span>).Skip&lt;User&gt;(pageSize);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> &#123;</span><br><span class="line">                temp = temp.OrderByDescending&lt;User, s&gt;(orderByLambda).Skip&lt;User&gt;(pageIndex - <span class="number">1</span>).Skip&lt;User&gt;(pageSize);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">return</span> temp;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><img src="7.png" alt="avatar"></p>
<p>IBLL层<br>
IBaseService.cs (业务接口)</p>
<figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> IDAL;</span><br><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">namespace</span> IBLL</span><br><span class="line">&#123;</span><br><span class="line">     <span class="keyword">public</span>  interface IBaseService&lt;T&gt; where T:<span class="class"><span class="keyword">class</span> ,<span class="title">new</span>()</span></span><br><span class="line"><span class="class">    &#123;</span></span><br><span class="line">        IDbSession CurrentDBSession &#123; <span class="built_in">get</span>; &#125;</span><br><span class="line">       IBaseDal&lt;T&gt; CurrentDal &#123; <span class="built_in">get</span>; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="function">IQueryable&lt;T&gt; <span class="title">LoadEntities</span><span class="params">(System.Linq.Expressions.Expression&lt;Func&lt;T, <span class="keyword">bool</span>&gt;&gt; wherelambda)</span></span>;</span><br><span class="line">        IQueryable&lt;T&gt; LoadPageEntities&lt;s&gt;(<span class="keyword">int</span> pageIndex, <span class="keyword">int</span> pageSize, out <span class="keyword">int</span> totalCount, System.Linq.Expressions.Expression&lt;Func&lt;T, <span class="keyword">bool</span>&gt;&gt; wherelambda, System.Linq.Expressions.Expression&lt;Func&lt;T, s&gt;&gt; orderByLambda, <span class="keyword">bool</span> isasc);</span><br><span class="line">        <span class="function"><span class="keyword">bool</span> <span class="title">DeleteEntity</span><span class="params">(T entity)</span></span>;</span><br><span class="line">        <span class="function"><span class="keyword">bool</span> <span class="title">EditEntity</span><span class="params">(T entity)</span></span>;</span><br><span class="line">        <span class="function">T <span class="title">AddEntity</span><span class="params">(T entity)</span></span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>IUserService.cs用户业务接口</p>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">using System;</span><br><span class="line">using System.Collections.Generic;</span><br><span class="line">using System.Linq;</span><br><span class="line">using System.Text;</span><br><span class="line">using System.Threading.Tasks;</span><br><span class="line">using Model;</span><br><span class="line">namespace IBLL</span><br><span class="line">&#123;</span><br><span class="line">     public <span class="built_in"> interface </span>IUserService:IBaseService&lt;User&gt;</span><br><span class="line">    &#123;</span><br><span class="line">       </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>BLL层<br>
BaseService.cs(业务基类 实现IBaseService接口）</p>
<figure class="highlight arduino"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> IDAL;</span><br><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"><span class="keyword">using</span> Model;</span><br><span class="line"><span class="keyword">using</span> DALFactory;</span><br><span class="line"><span class="keyword">namespace</span> BLL</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//接口的成员不用声明为 public,private ,protected</span></span><br><span class="line">    <span class="comment">//接口的实现需要设置为public</span></span><br><span class="line">    <span class="keyword">public</span> abstract  <span class="class"><span class="keyword">class</span> <span class="title">BaseService</span>&lt;T&gt; <span class="title">where</span> <span class="title">T</span>:</span><span class="class"><span class="keyword">class</span> ,<span class="title">new</span>()</span></span><br><span class="line"><span class="class">    &#123;</span></span><br><span class="line">       <span class="keyword">public</span> IDbSession CurrentDBSession</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="built_in">get</span></span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">return</span> DBSessionFactory.CreateDBSession();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">public</span> IBaseDal&lt;T&gt; CurrentDal &#123; <span class="built_in">get</span>; <span class="built_in">set</span>; &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> abstract <span class="keyword">void</span> <span class="title">SetCurrentDal</span><span class="params">()</span></span>;<span class="comment">//这个抽象方法用于(子类)实现， 当前Service是哪一类，需要 哪个DAL。（CurrentDal）（多态）</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="title">BaseService</span><span class="params">()</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            SetCurrentDal();</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> IQueryable&lt;T&gt; <span class="title">LoadEntities</span><span class="params">(System.Linq.Expressions.Expression&lt;Func&lt;T, <span class="keyword">bool</span>&gt;&gt; wherelambda)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="comment">//return  CurrentDBSession.userdal.LoadEntities(wherelambda);</span></span><br><span class="line">            <span class="keyword">return</span> CurrentDal.LoadEntities(wherelambda);</span><br><span class="line">        &#125;</span><br><span class="line">       <span class="keyword">public</span>   IQueryable&lt;T&gt; LoadPageEntities&lt;s&gt;(<span class="keyword">int</span> pageIndex, <span class="keyword">int</span> pageSize, out <span class="keyword">int</span> totalCount, System.Linq.Expressions.Expression&lt;Func&lt;T, <span class="keyword">bool</span>&gt;&gt; wherelambda, System.Linq.Expressions.Expression&lt;Func&lt;T, s&gt;&gt; orderByLambda, <span class="keyword">bool</span> isasc)</span><br><span class="line">        &#123;</span><br><span class="line">          <span class="keyword">return</span>  <span class="keyword">this</span>.CurrentDal.LoadPageEntities&lt;s&gt;(pageIndex, pageSize,out totalCount, wherelambda, orderByLambda, isasc);</span><br><span class="line">        &#125;</span><br><span class="line">       <span class="function"><span class="keyword">public</span>  <span class="keyword">bool</span> <span class="title">DeleteEntity</span><span class="params">(T entity)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">          <span class="keyword">this</span>.CurrentDal.DeleteEntity(entity);</span><br><span class="line">            <span class="keyword">return</span> CurrentDBSession.SaveChanges();</span><br><span class="line">                </span><br><span class="line">        &#125;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">bool</span> <span class="title">EditEntity</span><span class="params">(T entity)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">             CurrentDal.EditEntity(entity);</span><br><span class="line">            <span class="keyword">return</span> CurrentDBSession.SaveChanges();</span><br><span class="line">        &#125;</span><br><span class="line">       <span class="function"><span class="keyword">public</span> T <span class="title">AddEntity</span><span class="params">(T entity)</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">             CurrentDal.AddEntity(entity);</span><br><span class="line">             CurrentDBSession.SaveChanges();</span><br><span class="line">            <span class="keyword">return</span> entity;</span><br><span class="line">        &#125;</span><br><span class="line"> </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>UserService.cs(继承BaseService,实现IBaseService)</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> System;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">using</span> System.Linq;</span><br><span class="line"><span class="keyword">using</span> System.Text;</span><br><span class="line"><span class="keyword">using</span> System.Threading.Tasks;</span><br><span class="line"><span class="keyword">using</span> Model;</span><br><span class="line"><span class="keyword">using</span> IBLL;</span><br><span class="line"><span class="keyword">namespace</span> BLL</span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//BaseService&lt;User&gt;实现了 IUserService</span></span><br><span class="line">    <span class="comment">//UserService继承了BaseService&lt;User&gt;,实现了IUserSerivce</span></span><br><span class="line">   <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserService</span> :</span> BaseService&lt;User&gt;,IUserService</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">void</span> <span class="title">SetCurrentDal</span><span class="params">()</span></span></span><br><span class="line"><span class="function">        </span>&#123;</span><br><span class="line">            <span class="keyword">this</span>.CurrentDal = <span class="keyword">this</span>.CurrentDBSession.userdal;<span class="comment">//多态</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">//public void add(User u)</span></span><br><span class="line">        <span class="comment">//&#123;</span></span><br><span class="line">        <span class="comment">//    this.CurrentDal.AddEntity(u);</span></span><br><span class="line">        <span class="comment">//    this.CurrentDBSession.SaveChanges();</span></span><br><span class="line">        <span class="comment">//&#125;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>到此项目搭建基本完成。<br>
由于让业务层和UI层解耦，还需要使用Spring.Net进行依赖注入和控制反转。<br>
这里需要注意Expressions是表达式 Func 是Lambda.<br>
IQuerable有延时加载。一般DAL返回IQuerable给业务层。业务层再使用IEmuerable.</p>
<hr>
<!-- Place this tag in your head or just before your close body tag. -->
<script async defer src="https://buttons.github.io/buttons.js"></script>
<!-- Place this tag where you want the button to render. -->
<p>Please <a class="github-button" href="https://github.com/xyzko1/myblog" data-icon="octicon-star" aria-label="Star xyzko1/myblog on GitHub" target="_blank" rel="noopener">Star</a> this Project if you like it! <a class="github-button" href="https://github.com/xyzko1" aria-label="Follow @xyzko1 on GitHub" target="_blank" rel="noopener">Follow</a> would also be appreciated!<br>
Peace!</p>

                

                <hr>
                <!-- Pager -->
                <ul class="pager">
                    
                        <li class="previous">
                            <a href="/2019/04/14/分布式、集群、负载均衡、弹性、云计算、失效迁移/" data-toggle="tooltip" data-placement="top" title="分布式、集群、负载均衡、弹性、云计算、失效迁移">&larr; Previous Post</a>
                        </li>
                    
                    
                </ul>

                <!-- duoshuo Share start -->
                
                <!-- 多说 Share end-->

                <!-- 多说评论框 start -->
                
                <!-- 多说评论框 end -->

                <!-- disqus comment start -->
                
                    <div class="comment">
                        <div id="disqus_thread" class="disqus-thread"></div>
                    </div>
                
                <!-- disqus comment end -->
            </div>
            
            <!-- Tabe of Content -->
            <!-- Table of Contents -->

    
      <aside id="sidebar">
        <div id="toc" class="toc-article">
        <strong class="toc-title">Contents</strong>
        
          <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#null"><span class="toc-nav-number">1.</span> <span class="toc-nav-text">正文</span></a></li></ol>
        
        </div>
      </aside>
    

                
            <!-- Sidebar Container -->
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                
                <section>
                    <!-- no hr -->
                    <h5><a href="/tags/">FEATURED TAGS</a></h5>
                    <div class="tags">
                       
                          <a class="tag" href="/tags/#Hexo" title="Hexo">Hexo</a>
                        
                          <a class="tag" href="/tags/#Blog" title="Blog">Blog</a>
                        
                    </div>
                </section>
                

                <!-- Friends Blog -->
                
                <hr>
                <h5>FRIENDS</h5>
                <ul class="list-inline">

                    
                        <li><a href="http://beantech.org" target="_blank">Bean Tech</a></li>
                    
                        <li><a href="http://blog.kaijun.rocks" target="_blank">Kaijun&#39;s Blog</a></li>
                    
                        <li><a href="http://huangxuan.me" target="_blank">Hux Blog</a></li>
                    
                        <li><a href="#" target="_blank">It Helps SEO</a></li>
                    
                </ul>
                
            </div>
        </div>
    </div>
</article>




<!-- disqus embedded js code start (one page only need to embed once) -->
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES * * */
    var disqus_shortname = "your-disqus-ID";
    var disqus_identifier = "https://xyzko1.github.io/2018/02/01/ASP.NET MVC+EF 项目架构搭建/";
    var disqus_url = "https://xyzko1.github.io/2018/02/01/ASP.NET MVC+EF 项目架构搭建/";

    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<!-- disqus embedded js code start end -->




<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>
<!-- anchor-js, Doc:http://bryanbraun.github.io/anchorjs/ -->
<script>
    async("https://cdn.bootcss.com/anchor-js/1.1.1/anchor.min.js",function(){
        anchors.options = {
          visible: 'hover',
          placement: 'left',
          icon: 'ℬ'
        };
        anchors.add().remove('.intro-header h1').remove('.subheading').remove('.sidebar-container h5');
    })
</script>
<style>
    /* place left on bigger screen */
    @media all and (min-width: 800px) {
        .anchorjs-link{
            position: absolute;
            left: -0.75em;
            font-size: 1.1em;
            margin-top : -0.1em;
        }
    }
</style>



    <!-- Footer -->
    <!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                
                
                

                

                
                    <li>
                        <a target="_blank" href="https://www.facebook.com/xyzko1">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                
                    <li>
                        <a target="_blank"  href="https://github.com/xyzko1">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                
                    <li>
                        <a target="_blank"  href="https://www.linkedin.com/in/xyzko1">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-linkedin fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                </ul>
                <p class="copyright text-muted">
                    Copyright &copy; xyzko1 2021 
                    <br>
                    Theme by <a href="http://huangxuan.me">Hux</a> 
                    <span style="display: inline-block; margin: 0 5px;">
                        <i class="fa fa-heart"></i>
                    </span> 
                    re-Ported by <a href="http://beantech.org">BeanTech</a> | 
                    <iframe
                        style="margin-left: 2px; margin-bottom:-5px;"
                        frameborder="0" scrolling="0" width="91px" height="20px"
                        src="https://ghbtns.com/github-btn.html?user=YenYuHsuan&repo=hexo-theme-beantech&type=star&count=true" >
                    </iframe>
                </p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="/js/bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="/js/hux-blog.min.js"></script>


<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!-- 
     Because of the native support for backtick-style fenced code blocks 
     right within the Markdown is landed in Github Pages, 
     From V1.6, There is no need for Highlight.js, 
     so Huxblog drops it officially.

     - https://github.com/blog/2100-github-pages-now-faster-and-simpler-with-jekyll-3-0  
     - https://help.github.com/articles/creating-and-highlighting-code-blocks/    
-->
<!--
    <script>
        async("http://cdn.bootcss.com/highlight.js/8.6/highlight.min.js", function(){
            hljs.initHighlightingOnLoad();
        })
    </script>
    <link href="http://cdn.bootcss.com/highlight.js/8.6/styles/github.min.css" rel="stylesheet">
-->


<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("https://xyzko1.github.io/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

<!--fastClick.js -->
<script>
    async("https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>


<!-- Google Analytics -->


<script>
    // dynamic User by Hux
    var _gaId = 'UA-XXXXXXXX-X';
    var _gaDomain = 'yoursite';

    // Originial
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', _gaId, _gaDomain);
    ga('send', 'pageview');
</script>




<!-- Baidu Tongji -->






	<a id="rocket" href="#top" class=""></a>
	<script type="text/javascript" src="/js/totop.js?v=1.0.0" async=""></script>
    <script type="text/javascript" src="/js/toc.js?v=1.0.0" async=""></script>
<!-- Image to hack wechat -->
<img src="https://xyzko1.github.io/img/icon_wechat.png" width="0" height="0" />
<!-- Migrate from head to bottom, no longer block render and still work -->

</body>

</html>
